package com.car.controller;

import com.car.entity.User;
import com.car.entity.Vip;
import com.car.service.IntegralService;
import com.car.service.UserService;
import com.car.util.Fianl;
import com.car.vo.IntegralVo;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("/vip")
@Controller
public class VipController {
	
	@Autowired
	UserService userService;
	@Autowired
	IntegralService integralService;
	
	@RequestMapping("/membees")
	public String vipScoreUpd(HttpSession session,Model model){
		Fianl fina = new Fianl();
		User user = (User) session.getAttribute("loginSuccess");
		User users = userService.selectByPrimaryKey(user.getUserId());
		int nums = integralService.sumIntegral(users.getUserId()); //总共积分
		
		if(nums>=fina.getLevelPicYinka()){
			users.setVipId(2);
		}
		if(nums>=fina.getLevelPicJinka()){
			
			users.setVipId(3);
		}

		if(nums>=fina.getLevelPicBaijinka()){
			
			users.setVipId(4);
		}

		if(nums>=fina.getLevelPicZuanshi()){
			
			users.setVipId(5);
		}
		
		if(nums<fina.getLevelPicYinka()){
			users.setVipId(1);
		}
		int updVipId = userService.updVip(users.getVipId(), users.getUserId());
		
		List<IntegralVo> list = integralService.selectByUserIdToOrderId(users.getUserId());
		
		//model.addAttribute("level", users.getVipId());
		model.addAttribute("lists", list.isEmpty()?null:list);
		model.addAttribute("countIntreal", nums);
		model.addAttribute("fian", fina);
		model.addAttribute("user", users);
		return "H5phone/membeeslevel";
	}

}